package cn.ncupyh.soft.opera;

import cn.ncupyh.soft.book.Book;
import cn.ncupyh.soft.book.BookList;

import java.util.Scanner;

/**
 * @version 1.8
 * @Author Djx_hmbb
 * @Date 2023/7/22 9:59
 * @注释:
 */
public class BorrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书!");
        System.out.println("请输入你要借阅的图书名称:");
        Scanner s  = new Scanner(System.in);
        String bookName = s.nextLine();//输入书名
        int currentSize = bookList.getUsedSize();//初始数量
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(bookName)){
                if(book.isBorrowed()==false){
                    System.out.print("找到了这本书:");
                    System.out.println(book);
                    book.setBorrowed(true);
//                    bookList.setUsedSize(currentSize-1);
                    System.out.println("借阅成功!");
                    System.out.println(book);
                    return;
                }else {
                    System.out.println("该书已被借出!");
                    return;
                }
            }
        }
        System.out.println("查无此书!");
    }
}
